package com.yztc.ui.cook;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;

import com.bumptech.glide.Glide;
import com.yztc.bean.cook.CateGoryListBean;
import com.yztc.bean.cook.CookerBean;
import com.yztc.chunboapp.R;
import com.yztc.ui.cook.jiekou.OnItemClickListener;
import com.yztc.utils.ImageHelper;

import java.util.List;

/**
 * Created by Administrator on 2016/10/9.
 */

public class CategoryAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private List<CateGoryListBean> list;
    private LayoutInflater inflater;
    private OnItemClickListener listener;
    public void setListener(OnItemClickListener listener) {
        this.listener = listener;
    }
    public CategoryAdapter(Context context, List<CateGoryListBean> list){
        this.context=context;
        this.list=list;
        Log.i("wx","-------list   Categoty-------"+list.size());
        inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=inflater.inflate(R.layout.fragment_cook_category,parent,false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        final MyViewHolder mHolder= (MyViewHolder) holder;
        ImageHelper.getNormalImage(context,list.get(position).getPicUrl(),mHolder.iv_cooker);
        if(listener!=null){
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos=mHolder.getLayoutPosition();
                    listener.onItemClick(holder.itemView,pos);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class MyViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv_cooker;
        public MyViewHolder(View itemView) {
            super(itemView);
            iv_cooker=
                    (ImageView) itemView.findViewById(R.id.cook_category);
        }
    }
}
